﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Collections;
using System.Reflection;
using System.ComponentModel;

/// <summary>
/// 薪水范围
/// </summary>
public enum ShalaryEnum : int
{
    /// <summary>
    /// 面议
    /// </summary>
    [Description("面议")]
    Salary = 1,
    /// <summary>
    /// 1500以下
    /// </summary>
    [Description("1500以下")]
    Salary1K5 = 2,
    /// <summary>
    /// 1500至1999
    /// </summary>
    [Description("1500至1999")]
    Salary1K5_2K = 3,
    /// <summary>
    /// 2000至2999
    /// </summary>
    [Description("2000至2999")]
    Salary2K = 4,
    /// <summary>
    /// 3000至4499
    /// </summary>
    [Description("3000至4499")]
    Salary3K_4K5 = 5,
    /// <summary>
    /// 4500至5999
    /// </summary>
    [Description("4500至5999")]
    Salary4K5_6K = 6,
    /// <summary>
    /// 6000至7999
    /// </summary>
    [Description("6000至7999")]
    Salary6K_8K = 7,
    /// <summary>
    /// 8000至9999
    /// </summary>
    [Description("8000至9999")]
    Salary8K_1W = 8,
    /// <summary>
    /// 10000至14999
    /// </summary>
    [Description("10000至14999")]
    Salary1W_1W5 = 9,
    /// <summary>
    /// 15000至19999
    /// </summary>
    [Description("15000至19999")]
    Salary1W5_2W = 10,
    /// <summary>
    /// 20000至29999
    /// </summary>
    [Description("20000至29999")]
    Salary2W = 11,
    /// <summary>
    /// 30000至49999
    /// </summary>
    [Description("30000至49999")]
    Salary3W_4W = 12,
    /// <summary>
    /// 50000及以上
    /// </summary>
    [Description("50000及以上")]
    Salary5W = 13
}

/// <summary>
/// 学历要求
/// </summary>
public enum RequiredDegreeEnum : int
{
    ///// <summary>
    ///// 不限
    ///// </summary>
    //[Description("不限")]
    //None = 1,
    /// <summary>
    /// 博士后
    /// </summary>
    [Description("博士后")]
    BoShiHou = 1,
    /// <summary>
    /// 博士
    /// </summary>
    [Description("博士")]
    BoShi = 2,
    /// <summary>
    /// MBA
    /// </summary>
    [Description("MBA")]
    MBA = 3,
    /// <summary>
    /// 硕士
    /// </summary>
    [Description("硕士")]
    ShuoShi = 4,
    /// <summary>
    /// 本科
    /// </summary>
    [Description("本科")]
    BenKe = 5,
    /// <summary>
    /// 大专
    /// </summary>
    [Description("大专")]
    DaZhuan = 6,
    /// <summary>
    /// 其他
    /// </summary>
    [Description("其他")]
    Other = 7
}

/// <summary>
/// 性别
/// </summary>
public enum SexEnum : int
{
    /// <summary>
    /// 不限
    /// </summary>
    [Description("不限")]
    None = 0,
    /// <summary>
    /// 男性
    /// </summary>
    [Description("男性")]
    Man = 1,
    /// <summary>
    /// 女性
    /// </summary>
    [Description("女性")]
    Woman = 2
}

/// <summary>
/// 工作年限
/// </summary>
public enum WorkExperienceEnum : int
{
    /// <summary>
    /// 不限
    /// </summary>
    [Description("不限")]
    None = 1,
    /// <summary>
    /// 应届生
    /// </summary>
    [Description("应届生")]
    Work0 = 2,
    /// <summary>
    /// 一至两年
    /// </summary>
    [Description("一至两年")]
    Work1_2 = 3,
    /// <summary>
    /// 二至三年
    /// </summary>
    [Description("二至三年")]
    Work2_3 = 4,
    /// <summary>
    /// 三至五年
    /// </summary>
    [Description("三至五年")]
    Work3_5 = 5,
    /// <summary>
    /// 五至十年
    /// </summary>
    [Description("五至十年")]
    Work5_10 = 6,
    /// <summary>
    /// 十年以上
    /// </summary>
    [Description("十年以上")]
    Work10 = 7
}

/// <summary>
/// 枚举扩展
/// </summary>
public static class EnumExte
{
    private static Dictionary<WorkExperienceEnum, string> _workExperienceEnum = null;
    private static Dictionary<RequiredDegreeEnum, string> _requiredDegreeEnum = null;
    private static Dictionary<SexEnum, string> _sexEnum = null;
    private static Dictionary<ShalaryEnum, string> _shalaryEnum = null;

    /// <summary>
    /// 工作年限枚举列表
    /// </summary>
    public static Dictionary<WorkExperienceEnum, string> WorkExperienceEnums
    {
        get
        {
            if (_workExperienceEnum == null)
                _workExperienceEnum = Enum<WorkExperienceEnum>.AsEnumerable().ToDictionary(p => p, p => p.GetDesc());

            return _workExperienceEnum;
        }
    }
    /// <summary>
    /// 学历要求枚举列表
    /// </summary>
    public static Dictionary<RequiredDegreeEnum, string> RequiredDegreeEnums
    {
        get
        {
            if (_requiredDegreeEnum == null)
                _requiredDegreeEnum = Enum<RequiredDegreeEnum>.AsEnumerable().ToDictionary(p => p, p => p.GetDesc());

            return _requiredDegreeEnum;
        }
    }
    /// <summary>
    /// 性别枚举列表
    /// </summary>
    public static Dictionary<SexEnum, string> SexEnums
    {
        get
        {
            if (_sexEnum == null)
                _sexEnum = Enum<SexEnum>.AsEnumerable().ToDictionary(p => p, p => p.GetDesc());

            return _sexEnum;
        }
    }
    /// <summary>
    /// 薪水范围枚举列表
    /// </summary>
    public static Dictionary<ShalaryEnum, string> ShalaryEnums
    {
        get
        {
            if (_shalaryEnum == null)
                _shalaryEnum = Enum<ShalaryEnum>.AsEnumerable().ToDictionary(p => p, p => p.GetDesc());

            return _shalaryEnum;
        }
    }

    /// <summary>
    /// 获取枚举变量值的描述信息Description
    /// </summary>
    /// <param name="obj">枚举变量</param>
    /// <returns>返回描述信息</returns>
    public static string GetDesc(this Enum obj)
    {
        if (obj == null)
        {
            return string.Empty;
        }
        try
        {
            Type _enumType = obj.GetType();
            FieldInfo fi = _enumType.GetField(Enum.GetName(_enumType, obj));
            DescriptionAttribute dna = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));

            if (dna != null && !string.IsNullOrEmpty(dna.Description))
            {
                return dna.Description;
            }
        }
        catch { }
        //return obj.ToString();
        return string.Empty;
    }

    /// <summary>
    /// 获取枚举键值
    /// </summary>
    /// <param name="obj">枚举变量</param>
    /// <returns>返回枚举键值</returns>
    public static string GetKey(this Enum obj)
    {
        if (obj == null)
        {
            return string.Empty;
        }
        return Enum.GetName(obj.GetType(), obj);
    }
    /// <summary>
    /// 获取枚举键值
    /// </summary>
    /// <param name="obj">枚举变量</param>
    /// <returns>返回枚举键值</returns>
    public static int GetValue(this Enum obj)
    {
        if (obj == null)
        {
            return default(int);
        }
        return (int)Enum.Parse(obj.GetType(), obj.ToString());
    }
}

/// <summary>
/// T 类型枚举列表
/// </summary>
/// <typeparam name="T">枚举类型</typeparam>
public class Enum<T> : IEnumerable<T>
{
    #region Business Methods
    /// <summary>
    /// 返回类型为 IEnumerable&lt;T&gt; 的输入。
    /// </summary>
    /// <returns>类型为 IEnumerable&lt;T&gt; 的序列。</returns>
    public static IEnumerable<T> AsEnumerable()
    {
        return new Enum<T>();
    }
    #endregion

    #region IEnumerable<T> 成员

    /// <summary>
    /// 返回一个循环访问集合的枚举数。
    /// </summary>
    /// <returns>可用于循环访问集合的 IEnumerator&lt;T&gt; 。</returns>
    public IEnumerator<T> GetEnumerator()
    {
        return Enum.GetValues(typeof(T))
            .OfType<T>()
            .AsEnumerable()
            .GetEnumerator();
    }

    #endregion

    #region IEnumerable 成员

    /// <summary>
    /// 返回一个循环访问集合的枚举数。
    /// </summary>
    /// <returns>可用于循环访问集合的 IEnumerator 。</returns>
    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

    #endregion

    #region IEnumerable<T> 成员

    /// <summary>
    /// 返回一个循环访问集合的枚举数。
    /// </summary>
    /// <returns>
    /// <returns>可用于循环访问集合的 IEnumerator&lt;T&gt; 。</returns>
    IEnumerator<T> IEnumerable<T>.GetEnumerator()
    {
        return GetEnumerator();
    }

    #endregion
}